#!/bin/sh
set -e

delete_unchanged() {
  if [ -e "$1" ] && echo "$2 $1" | md5sum --check --status; then
    echo "Removing unchanged configuration file $1"
    rm -f "$1"
  fi
}

backup_conffile() {
  if [ -e "$1" ]; then
    echo "Moving configuration file $1 to $1.dpkg-bak"
    mv -f "$1" "$1".dpkg-bak
  fi
}

case "$1" in
  install|upgrade)
    # clean up files we no longer ship
    delete_unchanged "/etc/default/pdns-recursor" a09916ceb17db9a49ac8cfa84790bf3b
    delete_unchanged "/etc/default/pdns-recursor" 076b21b9b76d7ffecc918af47d2963c6
    backup_conffile "/etc/default/pdns-recursor"
    delete_unchanged "/etc/init.d/pdns-recursor" e2ea0586c3d99fdbafb76483a769b964
    delete_unchanged "/etc/init.d/pdns-recursor" fb608ec5edc3d068213bac3480782355
    backup_conffile "/etc/init.d/pdns-recursor"
  ;;
esac

#DEBHELPER#
